//
//  ComplaintViewController.m
//  wtshoppingcite
//
//  Created by TW on 15-1-15.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "ComplaintViewController.h"
#import "PariseViewController.h"
#import "RepairHistoryDetailViewController.h"
#import "CommentTableView.h"
#import "ShareHeaderView.h"
#import "NetServiseCommonData.h"
#import "ComplainTableView.h"

@interface ComplaintViewController ()<CustomTabItemViewDelegate,UIActionSheetDelegate,UITableViewEventsDelegate>

@property(nonatomic,strong) CustomTabItemView *tabItemView;
@property(nonatomic,strong) CommentTableView *commentTableView;
@property(nonatomic,strong) ShareHeaderView *headerView;
@property(nonatomic,strong)NSArray* commentArray;
@property(nonatomic,strong)NSArray* dataSourse;


@property(nonatomic,strong)ComplainTableView* tableView;
@property(nonatomic,strong)NSDictionary* infoData;
@property(nonatomic,strong)NSString* status;
@property(nonatomic,strong)UIActionSheet *actionSheet;

@end

@implementation ComplaintViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setRightButton:@"举报" sel:@selector(reportAction) viewController:self];
    
    self.tabItemView = [[CustomTabItemView alloc] initWithFrame:CGRectMake(0, 0, 200, 45) type:TAB_ITEM_TYPE_CORWIDTH];
    self.tabItemView.backgroundColor = [UIColor whiteColor];
    self.tabItemView.delegate = self;
    [self.tabItemView initWithBackColorCornerItemNames:@[@"帖子详情",@"处理进度"]];
    [self.view addSubview:self.tabItemView];
    self.navigationItem.titleView = self.tabItemView;
    
    [self initWithCard];
    // Do any additional setup after loading the view.
}

#pragma mark CustomTabItemViewDelegate
- (void)tabItemSelectedAtIndex:(int)index tabItem:(CustomTabItemView *)view
{
    if (index == 0) {
        
        [self initWithCard];
        
    }else if (index == 1){
        
        [self initWithProgress];
        
    }
    NSLog(@"select index :%d",index);
}


#pragma mrak 帖子详情
-(void) initWithCard{
    [self startDataRequest];
    [self commentData];
    
    _commentTableView = [[CommentTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _commentTableView.eventsDelegate = self;
//    _commentTableView.isMore = YES;
//    _commentTableView.isNeedTorefresh = YES;
    _commentTableView.data = _commentArray;
    [self.view addSubview:_commentTableView];
    
 //   PariseModel *pariseModel = [[PariseModel alloc]initWithPariseInfo:_dataSourse[0]];
    _headerView = [[ShareHeaderView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 440)];
   // _headerView.pariseModel = pariseModel;
    _commentTableView.tableHeaderView = _headerView;
}


#pragma mark 处理进度
-(void)initWithProgress{
    
    [self startProgressDataRequest];
    
    _tableView = [[ComplainTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _tableView.eventsDelegate = self;
    _tableView.isMore = YES;
    _tableView.status = _status;
    _tableView.infoData = _infoData;
    _tableView.isNeedTorefresh = YES;
    [self.view addSubview:_tableView];
    
    
    
}

#pragma mark 处理进度数据调用
-(void)startProgressDataRequest{
    
    _infoData = [NetServiseCommonData getRepairHistoryDetailData];
    _status = [_infoData[@"header"] objectForKey:@"status"];
    [_tableView reloadData];
}


#pragma mark 帖子详情数据调用
-(void)startDataRequest{
    
    NSDictionary* dic = [NetServiseCommonData getPariseData];
    _dataSourse = [dic objectForKey:@"list"];
}

-(void)commentData{
    
    NSDictionary* dic = [NetServiseCommonData getEvaluateData];
    _commentArray = [dic objectForKey:@"list"];
}



#pragma mark reportAction
-(void)reportAction{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    
    _actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"举报" otherButtonTitles:@"取消", nil];
    _actionSheet.tag = 100;
    _actionSheet.delegate = self;
    [_actionSheet showInView:view];
}

#pragma  mark uiactionsheet
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if(actionSheet.tag == 100){
        
        //举报
        if(buttonIndex == 0){
            
         //   [self getreport];
            
        }
        //取消
        else if(buttonIndex == 1){
            
            actionSheet.hidden = YES;
            
        }
    }else{
        
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    ;
}


- (void)viewWillDisappear:(BOOL)animated
{
    
    [super viewWillDisappear:animated];
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
